﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Pacoca
{
    class Sol
    {
        Vector2 posicao, vetor;
        float tempoDozeHoras;
        public static bool estadoDeNoite;
        Vector2 raio;
        float anguloGraus, anguloRadianos;

        public Sol()
        {
            estadoDeNoite = true;
            Recomecar();
        }
        public void Recomecar()
        {
            anguloGraus = -90;
            raio = new Vector2( (Game1.tamanhoTela.X/2) + Textura.texLua.Width/2,  (Game1.tamanhoTela.Y/2) + Textura.texLua.Width/2);
            vetor = Vector2.Zero;
            posicao = Vector2.Zero;
            tempoDozeHoras = 12 * ((60 * Anoitecer.tempoDoDia) / 24);

            if (estadoDeNoite)
                estadoDeNoite = false;
            else
                estadoDeNoite = true;
        }
        public void Update(GameTime gameTime)
        {
            KeyboardState keyBoardState = Keyboard.GetState();


            if (vetor.X >= 449)
                Recomecar();

            anguloGraus += 180 / tempoDozeHoras;
            anguloRadianos = anguloGraus * (float)Math.PI / 180;
            anguloRadianos *= (float)gameTime.ElapsedGameTime.TotalSeconds;

            vetor.Y = raio.Y * (float)-Math.Sin(anguloRadianos);
            vetor.X = raio.X * (float)-Math.Cos(anguloRadianos);

            Vector2 novaPosicao = new Vector2(Game1.tamanhoTela.X/2, 450);

            novaPosicao.X += vetor.X;
            novaPosicao.Y += vetor.Y;
     

            
            posicao.X = novaPosicao.X - Textura.texLua.Width / 2;
            posicao.Y = novaPosicao.Y - Textura.texLua.Height / 2;
        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if(estadoDeNoite)
                spriteBatch.Draw(Textura.texLua, posicao, Color.White);
            else
                spriteBatch.Draw(Textura.texSol, posicao, Color.White);

           // spriteBatch.DrawString(Textura.spriteFonte, "" + vetor.X + "     " + vetor.Y, new Vector2(100, 300), Color.White);
            //spriteBatch.DrawString(Textura.spriteFonte, "PosX : " + posicao.X + "    posY " + posicao.Y, new Vector2(100, 100), Color.White);
            //spriteBatch.DrawString(Textura.spriteFonte, "vETORx: " + vetor.X + "    RAIOx " + raio.X, new Vector2(100, 150), Color.White);
        }


    }
}
